<?php
# header of each page
function head($title='', $meta_description='', $meta_keywords='', $active='') {
header("Content-type: text/html; charset=UTF-8");
?>
<!DOCTYPE html>
<html>
<head>
<title><?=$title?></title>
<meta name="description" content="<?=$meta_description?>" />

<link rel="stylesheet" type="text/css" href="<?=HTML_BASE?>css/reset.css">
<link rel="stylesheet" type="text/css" href="<?=HTML_BASE?>css/style.css?v=1">
<script src="<?=HTML_BASE?>js/modernizr.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script>
<script src="<?=HTML_BASE?>js/script.js" type="text/javascript"></script>
</head>

<body>
<div id="wrap">
	<div id="wrapin">
		
		<div id="left">
			<div id="lang">
				
                <?php
                $sql = 'SELECT lang_id,Name,code FROM language WHERE published';
				$result_lang = query($sql);
				
				$hiper = '';
				if($_GET['prm1']) $hiper .= '/'.$_GET['prm1'];
				if($_GET['prm2']) $hiper .= '/'.$_GET['prm2'];
		
				while ($row_lang = mysql_fetch_object($result_lang)) {
						$act = '';
						if($row_lang->lang_id == $_SESSION['lang_id']) $act = 'class="active"';
						
						echo '<a '.$act.' title="'.$row_lang->Name.'" href="'.HTML_BASE.$row_lang->code.$hiper.'"><img src="'.HTML_BASE.'images/'.$row_lang->code.'.gif"><br>'.$row_lang->code.'</a>';
										
				}
				
				?>
                
			</div>
			
			<div id="info">
				<span>12th World Congress of Semiotics</span>
				Sofia 2014, 16-20 September<br>
				New Bulgarian University
			</div>
            
			<div id="menu">
				<?php
                
					
				
					
					
					function json_clean_decode($json, $assoc = true, $depth = 512, $options = 0) {
			
				$json = preg_replace("#(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|([\s\t]//.*)|(^//.*)#", '', $json);
				
				if(version_compare(phpversion(), '5.4.0', '>=')) {
					$json = json_decode($json, $assoc, $depth, $options);
				}
				elseif(version_compare(phpversion(), '5.3.0', '>=')) {
					$json = json_decode($json, $assoc, $depth);
				}
				else {
					$json = json_decode($json, $assoc);
				}
			
				return $json;
		}
		
		 
		 
		 $sql= "SELECT menuitems FROM menus WHERE menu_id = '6'";
		 $result = query($sql);
		 $row_m = mysql_fetch_object($result);
		 
		 $arr =  json_clean_decode($row_m->menuitems);
		 function create_ul($ar,$first)
		 {
				$menu_id = 6;
				echo '<ul>';
				
				
				foreach ($ar as $key => $value) {
				 
				
					$item = $value['id'];
					
					$sqlm = "SELECT parent_id,title FROM  menu_description 
						  WHERE menu_id = '".$menu_id."'AND item_id = '".$item."'
						  AND lang_id = '".$_SESSION['lang_id']."'
						 ";
				
					$rowm = mysql_fetch_object(query($sqlm)); 
				
					$sql_sef = "SELECT sef_url FROM  pages 
						  WHERE page_id = '".$rowm->parent_id."'
						 ";
					$row_sef = mysql_fetch_object(query($sql_sef));
					$parent = '';
					if($value['children']) $parent = 'class="isparent"';
					echo '<li '.$parent.'><a href="'.HTML_BASE.$_SESSION['lang'].'/'.$row_sef->sef_url.'">'.$rowm->title.'</a>';
					 
					if($value['children']) create_ul($value['children'],false);
					 
					echo '</li>';
				}
					
					
					echo '</ul>';
				
				
		 }
		 
		 create_ul($arr,true);
				
				
				?>
			</div>
			
			<div id="banner">
            	<?php 
				$datetime1 = new DateTime('now');
				$datetime2 = new DateTime('2014-3-1');
				
				if ($datetime1 < $datetime2) { ?>
				<a href="<?=HTML_BASE.$_SESSION['lang']?>/information">Registration before 28/2 <span>20% off</span></a>
                <?php } ?>
			</div>
			
		</div>
	
    
  
<?php	
}
function menue()
{
	?>
    
	<?php
}
# footer of each page
function foot($tmp='') {
?>
		
	
	
		</div><!--#right-->
		
	</div>
</div>
<div id="footerwrap">
	<div id="footer">
		<?php if($tmp == 'home'){?>
		<div class="buhal"></div>
		<?php }?>
		<div id="terms">
			<a href="<?=HTML_BASE.$_SESSION['lang']?>/faq">FAQ</a> |
			<a href="<?=HTML_BASE.$_SESSION['lang']?>/terms-and-conditions"><?=__Terms?></a>
		</div>
		<div id="footright">
			<div class="social">
				Follow us on:
				<a href="<?=__FACEBOOK?>" target="_blank" class="fb"></a>
				<a href="https://twitter.com/Semio2014" target="_blank" class="tw"></a>
				<a href="http://www.linkedin.com/groups/Semio2014-IASS-AIS-world-congress-6530163" target="_blank" class="in"></a>
				<a href="https://plus.google.com/communities/110435620336186324219" target="_blank" class="gl"></a>
			</div>
			<div id="copy">
				Copyright © New Semiotics 2013. All rights reserved.
			</div>
		</div>
	</div>
</div>
</body>
</html>
 
        
<?php
}

# a redirecting function that adds the session ID if cookies are disabled and stops the execution of the script
function redirect($location) {
	if (!$location) error("Missing arguments.");

	$a = parse_url($location);
	if (!isset($a['query'])) {
		$a['query'] = '';
	}
	
	$session_delimiter = ($a['query'])?'&':'?';
	header("Location: $location".addsession($session_delimiter));
	exit;
}

# adding the session_id when cookies are disabled
function addsession($symbol="?") {
	return (!isset($_COOKIE[session_name()])&&session_id())?$symbol.session_name()."=".session_id():"";
}

function escape($string,$encoding=false) {
  return mysql_real_escape_string( (($encoding)?encoding($string):$string) );
}

function encoding($string) {
  return iconv('ISO-8859-1', 'UTF-8', $string);
}

function sth($string) {
  return htmlspecialchars(stripslashes($string));
}

# checks whether an email is valid or not
function checkEmail($email) {
	return preg_match("/^[A-z0-9\.\-]+@(?:[A-z0-9\-]+\.)+[A-z0-9]{1,6}$/", $email);
}

# Cut a text to specified chracters length
function text_format($text, $length) {
	$str = '';
	$text_length = mb_strlen($text, "UTF-8");
	 
	if ($text_length < $length) {
		$str = $text;		
	} else {
		$position_end = strpos($text, ' ', $length);
		$str = substr($text, 0, ($position_end)?$position_end:$text_length);
	}
	
	return $str;
}

function text_format_blog($text, $length) {
	$str = '';
	$text_length = mb_strlen($text, "UTF-8");
	 
	if ($text_length < $length) {
		$str = $text;		
	} else {
		$position_end = strpos($text, '<hr />', $length);
		$str = substr($text, 0, ($position_end)?$position_end:$text_length);
	}
	
	return $str;
}


# general error function
function error($s="An error occured.") {
  if (!headers_sent()) {
    head("Error");
    echo "<table cellpadding=4 width=".SITE_WIDTH." align=center border=0><tr><td align=center class=title>$s</td></tr></table>";
    foot();
  }
  else
    echo $s;
  exit;
}

# debug function for dumping a variable value
function pp($var, $stop=false) {
  echo "<pre>";
  print_r($var);
  echo "</pre>";
  if ($stop) exit;
}

# Generate numbers
function generateNumber () {

  # start with a blank number
  $number = "";

  # define possible characters
  $possible = "0123456789"; 

  # pick a random character from the possible ones
  $number = substr($possible, mt_rand(0, strlen($possible)-1), 1);

  # done!
  return $number;

}



function getImage($path) {

  if(is_dir($path))
	{
	$dir = opendir( $path );
	$failnum = 0;
	while ( false != ( $filename = readdir($dir)))
		   { 
		   if (( $filename != "." ) and ( $filename != ".." ))
			  { 
				  if($failnum > 0)
				  {
					break;  
				  }else{
				  $f = HTML_BASE.$path.$filename;
				  }
				$failnum ++; 
			  }
		   }
	closedir($dir);
	return $f;
	}
  

}

function image_likes($album,$image)
{
	$sql = "SELECT ip FROM image_likes WHERE album_id = '".$album."' AND iamge = '".$image."'";
	$likes = query($sql);
	return mysql_numrows($likes);
}


function ip_likes($album,$image)
{
	$ip = $_SERVER["REMOTE_ADDR"];
	
	$sql = "SELECT ip FROM image_likes WHERE album_id = '".$album."' AND iamge = '".$image."' AND ip = '".$ip."'";
	$likes = query($sql);
	
	if(mysql_numrows($likes))
	{
		return 'class="like"';
	}
}


function image_title($album,$image)
{
	$sql_imds = "SELECT description FROM
						album_images_description
					WHERE
						album_id = '".$album."'
						AND image = '".$image."'
						AND lang_id = '".$_SESSION['lang_id']."'
					";
		$result_imds = query($sql_imds);
		$imds = mysql_fetch_object($result_imds);
		
		return  $imds->description;
}
# Convert numbers into strings with n zeros
function number_pad($number,$n) {
	return str_pad((int) $number,$n,"0",STR_PAD_LEFT);
}
?>